// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
//

#include <kllm/kai/model.h>
#include <kllm/kai/proto_helper.h>

namespace kllm {

    void KaiModels::list(const KaiRequest &req, KaiResponse&res) const {
        if(req.query_type() != QUERY_MODEL_LIST) {
            res.mutable_status()->set_code(static_cast<int32_t>(turbo::StatusCode::kInvalidArgument));
            res.mutable_status()->set_errmsg("invalid query type for list model, it should be as QUERY_MODEL_LIST");
            return;
        }
        res.set_model_alias(_context->params.model_alias);
        ModelEntity me;
        me.set_id(_context->params.model_alias);
        me.set_object("model");
        me.set_created(std::time(0));
        me.set_owned_by("kumo.ai");
        *me.mutable_meta() = _context->get_meta();
        res.set_query_type(req.query_type());
        *res.mutable_model_response()->add_models() = std::move(me);
        set_response_ok(res);
    }
}  // namespace kllm
